create database bbs
on
(
name='bbs',
filename='D:\text\bbs.mdf',
size=5MB,
maxsize=50MB,
filegrowth=10%
)
log on
(
name='bbs_log',
filename='D:\text\bbs_log.mdf',
size=5MB,
maxsize=50MB,
filegrowth=10%
)
go

use bbs

create table bbsUsers
(
[UID] int primary key identity(1,1),
uName varchar(10) unique not null,
uSex  varchar(2) not null check(uSex='男'or uSex='女'),
uAge int not null check(uAge>=15 and uAge<=60),
uPoint int not null check(uPoint>=0)
)
go

create table bbsSection
(
[sID] int primary key identity(1,1), 
sName  varchar(10)  not null,
sUid int references bbsUsers([UID])
)
go

create table bbsTopic
(
tID  int primary key identity(1,1),
tUID  int references bbsUsers([UID]) ,
tSID  int references bbsSection([sID]),
tTitle  varchar(100) not null,
tMsg  text not null,
tTime  datetime,
tCount  int
)
go

create table bbsReply
(
rID  int primary key identity(1,1),
rUID  int references bbsUsers([UID]),
rTID  int references bbsTopic(tID),
rMsg  text not null,
rTime  datetime
)
go

insert into bbsUsers values ('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2)

select uName,uPoint into bbsPoint from bbsUsers

insert into bbsSection values ('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3)

insert into bbsTopic values (2,1,'范跑跑','谁是范跑跑',2008-7-8,1),(3,1,'.NET','与JAVA的区别是什么呀？',2008-9-1,2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀？',2008-9-10,0)

insert into bbsReply values (1,2,'不知道呀',2008-9-2),(1,3,'不知道呀',2008-9-2),(3,1,'不知道',2009-10-1)

alter table bbsReply drop constraint FK__bbsReply__rUID__1BFD2C07
alter table bbsSection drop constraint FK__bbsSection__sUid__164452B1
alter table bbsTopic drop constraint FK__bbsTopic__tUID__1920BF5C
delete from bbsUsers where [UID]=2

update bbsUsers set uPoint=10 where [UID]=1

alter table bbsTopic drop constraint FK__bbsTopic__tSID__1A14E395
delete from bbsSection where [sID]=3

truncate table bbsReply
